package com.fuyin.commons.enums;

import lombok.Getter;

//对http请求状态码封装

@Getter
public enum ErrorCodeEnum {
    BAD_REQUEST(400, "请求出错"),
    UNAUTHORIZED(401, "用户没有登录"),
    FORBIDDEN(403, "用户没有权限"),
    NOT_FOUND(404, "资源未找到"),
    METHOD_NOT_ALLOWED(405, "客户端请求中的方法被禁止"),
    REQUEST_OVERTIME(408, "请求超时"),
    UNSUPPORTED_MEDIA_TYPE(415, "服务器无法处理请求附带的媒体格式"),
    INTERNAL_SERVER_ERROR(500, "后台异常");

    private final int errorCode;

    private final String errorMessage;

    ErrorCodeEnum(int errorCode, String errorMessage) {
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public static ErrorCodeEnum getEnumByCode(Integer errorCode) {
        for (ErrorCodeEnum enums : values()) {
            if (enums.getErrorCode() == errorCode) {
                return enums;
            }
        }
        return null;
    }
}
